package com.ax.base.drugstore.controller;

import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ax.base.common.utils.AjaxRes;
import com.ax.base.common.utils.Const;
import com.ax.base.common.utils.PageUtils;
import com.ax.base.drugstore.domain.BasePersonnel;
import com.ax.base.drugstore.service.DrugstoreManagerService;

@Controller
@RequestMapping("/sys/drugstoreManager")
public class DrugstoreManagerController {

	@Autowired
	DrugstoreManagerService drugstoreManagerService;
	
	/**
	 * 菜单页面的跳转
	 */
	@GetMapping()
	String drugAdministration(Model model) {
		return "drugstore/storemanager/storemanager";
	}

	/**
	 * 药房人员查询(模块:药店人员)
	 * 
	 * @param Map<String, Object> map
	 *           
	 * @return PageUtils
	 */
	@RequestMapping("/queryDrugStoreManager")
	@ResponseBody
	public AjaxRes queryDrugStoreManager(AjaxRes ajaxRes,@RequestParam Map<String, Object> params) {
		try {
			PageUtils basePersonnels = this.drugstoreManagerService.queryDrugStoreManagerSer(params);
			ajaxRes.setSucceed(basePersonnels,Const.DATA_SUCCEED);
		} catch (Exception e){
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	  }
	
	/**
	 * 药房人员增加(模块:药店人员)*跳转增加页面
	 * 
	 * @param 无
	 *           
	 * @return HTML
	 */
	@GetMapping("/add")
	String add(Model model) {
		return "drugstore/storemanager/add";
	}
	
	/**
	 * 药房人员保存(模块:药店人员)
	 * 
	 * @param BasePersonnel basePersonnel
	 *           
	 * @return SUCC
	 */
	@RequestMapping("/insertBasePersonnel")
	@ResponseBody
	public AjaxRes insertBasePersonnel(AjaxRes ajaxRes,BasePersonnel basePersonnel){
		try {
			this.drugstoreManagerService.insertBasePersonnelSer(basePersonnel);
			ajaxRes.setSucceed(Const.SAVE_SUCCEED);
		} catch (Exception e){
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}
	
	/**
	 * 药方人员修改(模块:药店人员)*跳转修改页面
	 * 
	 * @param Long id
	 *           
	 * @return HTML
	 */
	@GetMapping("/edit/{id}")
	String edit(Model model, @PathVariable("id") Long id) {
		model.addAttribute("storeManager",drugstoreManagerService.getBasePersonnelSer(id));
		return "drugstore/storemanager/edit";
	}
	
	/**
	 * 药方人员修改(模块:药店人员)
	 * 
	 * @param BasePersonnel basePersonnel
	 *           
	 * @return SUCC
	 */
	@RequestMapping("/updateBasePersonnel")
	@ResponseBody
	public AjaxRes updateBasePersonnel(AjaxRes ajaxRes,BasePersonnel basePersonnel){
		try {
			this.drugstoreManagerService.updateBasePersonnelSer(basePersonnel);
			ajaxRes.setSucceed(Const.UPDATE_SUCCEED);
		} catch (Exception e){
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}
	
}
